﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace Kimgwajang.MidnightPeach.Utilities
{
    public static class Utility
    {
        static Utility()
        {
            Version = Assembly.GetExecutingAssembly().GetName().Version;

            WorkingDirectory = Environment.CurrentDirectory;
        }

        public static Version Version { get; private set; }

        public static string WorkingDirectory { get; private set; }

        public static List<PackageFileInfo> GetPackageFiles()
        {
            var list = new List<PackageFileInfo>();
            DirectoryInfo folder = new DirectoryInfo(WorkingDirectory);
            GetPackageFilesCore(folder, list);

            return list;
        }

        private static void GetPackageFilesCore(DirectoryInfo folder, List<PackageFileInfo> list)
        {
            var files = folder.GetFiles("*.pds");
            foreach (var file in files)
                list.Add(new PackageFileInfo(file.Name.Substring(0, file.Name.Length - 4), file.FullName));

            var subFolders = folder.GetDirectories();
            foreach (var subFolder in subFolders)
                GetPackageFilesCore(subFolder, list);
        }
    }
}